<?php
/* ------------------------------------------------------------------------
 * AION-KOREA Admin Control Panel
 *
 * @version 1.0
 * @author Taro6222 (AION-KOREA Admin CP main Developer)
 * @link http://redmine.aionkorea.org/projects/ak-admin-cp
 * @license http://creativecommons.org/licenses/by-nc-sa/3.0/deed.ko
 * @APM http://www.apachefriends.org/en/xampp.html
 *
------------------------------------------------------------------------ */

ignore_user_abort( true );
//error_reporting( 0 );
//ini_set( 'memory_limit', -1 );
$memLimit = ini_get( 'memory_limit' );
if ($memLimit != '')
{
    switch ( $memLimit{strlen( $memLimit ) - 1} )
    {
        case 'G':
            $memLimit *= 1024;
        case 'M':
            $memLimit *= 1024;
        case 'K':
            $memLimit *= 1024;
    }
    if ( $memLimit != -1 && $memLimit < 44040192) /* 42*1024*1024 */
    {
        @ini_set( 'memory_limit', '42M' );
    }
}

//Send header information
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . 'GMT' );
header ("P3P : CP=\"ALL CURa ADMa DEVa TAIa OUR BUS IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC OTC\"");
header( 'Content-Type: text/html; charset=utf-8' );

//
define( '__GLOBAL_TEMPLATE_DIR',	'templates/default'	);
define( '__GLOBAL_CONFIG_FILE',		'var/config/config.php' );
define( '__GLOBAL_DEBUG_OUTPUT',	false	);
define( '__COMMON_TEMPLATE_ADMINCP','templates/admincp' );
define( '__COMMON_TEMPLATE_DIR',	'templates/common' );

//session
session_start();
session_name('admincp');
session_set_cookie_params(1440);

/* --- Autoload framework --- */
include_once( 'Zend/Loader/Autoloader.php'		);
include_once( 'library/class/Template.class.php');
include_once( 'library/ado.common.php'	);
include_once( 'library/ado.aion.php'	);

Zend_Loader_Autoloader::getInstance();

function __autoload( $className )
{
    Zend_Loader::autoload( $className );
}

// includes library files
$daoLibraryList = array(
	'dao.install.php',
	'dao.account.php',
	'dao.user.php',
	'dao.player.php',
);

foreach ($daoLibraryList as $key => $value) {
	$value = "library/{$value}";
	//
	if ( !file_exists( $value ) ) {
		//
		exit( "Critical File $value is not found." );
	}
	//
	include_once( $value );
}

//
if ( !file_exists( __GLOBAL_CONFIG_FILE ) || ( isset( $_SESSION['install_session_type'] ) ) ) {
	//header( 'Location: /?moduleToCall=install.config' );
	Zend_Registry::set('moduleName', 'install.config');
	include( 'modules/install.config.php' );
	exit;
}

// fix 24-05-2010
if (!extension_loaded('sqlite') && function_exists('dl')) {
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        @dl('php_sqlite.dll');
    } else {
        @dl('sqlite.so');
    }
}

//
ob_start();
$moduleName = 'index';
$controllerName = 'home';

//AdminCP 호출
if ( isset( $_GET['admincp'] ) ) {
	$getName = explode( '-', $_GET['admincp'] );
	if ( count( $getName ) == 2 ) {
		$moduleName = $getName[0];
		$controllerName = $getName[1];
	}

	$modulePath = "modules/admincp/{$moduleName}.{$controllerName}.php";
}

//Module 호출
if ( isset( $_GET['module'] ) ) {
	$getName = explode( '-', $_GET['module'] );
	if ( count( $getName ) == 2 ) {
		$moduleName = $getName[0];
		$controllerName = $getName[1];
	}
	else {
		$moduleName = $_GET['module'];
	}

	$modulePath = "modules/{$moduleName}.{$controllerName}.php";
}

Zend_Registry::set('templateName', "{$moduleName}.{$controllerName}");
Zend_Registry::set('moduleName', $moduleName);
//Zend_Registry::set('controllerName', $controllerName);

include( $modulePath );


//
$mainContents =& ob_get_contents();
ob_end_clean();


ob_start();

//admincp
if ( isset( $_GET['admincp'] ) ) {
	include( 'modules/admincp/index.frame.php' );
}
else {
	include( 'modules/index.frame.php' );
}
ob_end_flush();
